package com.wwp.tbshop.presenter;

import android.util.Log;

import com.wwp.tbshop.model.bean.CategoryVo;
import com.wwp.tbshop.view.fragment.category.CategoryBaseFragment;

import java.util.List;

import retrofit2.Call;

/**
 * Created by 楠GG on 2017/6/16.
 */

public class CategoryFragmentPresenter extends BasePresenter<CategoryVo> {
    private static final String TAG = "CategoryFragmentPresent";
    private CategoryBaseFragment mCategoryFragment;

    public CategoryFragmentPresenter(CategoryBaseFragment categoryFragment) {
        mCategoryFragment = categoryFragment;
    }

    public void loadCategoryInfo() {
        //mApiService是在父类中的
        Call<CategoryVo> categoryCall = mApiService.getCategoryInfo();
        //mCallback 是在父类中的
        categoryCall.enqueue(mCallback);
    }

    @Override
    protected void onServerBug(int code) {
        mCategoryFragment.onCategoryServerBug();
    }

    @Override
    protected void onConnectError(String message) {
        mCategoryFragment.onCategoryError();
    }

    @Override
    protected void onSuccess(CategoryVo categoryInfo) {
        if (categoryInfo == null){
            Log.e(TAG, "faild:没有获取到数据");
            return;
        }
        List<CategoryVo.CategoryBean> categoryItems = categoryInfo.getCategory();
        Log.e(TAG, "onSuccess"+categoryItems.size());
        mCategoryFragment.onCategorySuccess(categoryItems);
    }
}
